<template>
        <form-bo-list-preview @onRefresh="onRefresh" :key="key" ref="preview" :alias="alias" :pmtAlias="pmtAlias" :params="params" :appId="queryAppId"/>
</template>

<script>
/**
 * 树
 */
import FormBoListPreview from "@/views/modules/form/formBoList/FormBoListPreview";
import FormCustomPublic from "../FormCustomPublic";
import BusEvent from "../BusEvent";
import Util from "@/js/Util";
export default {
    name: "TreeView",
    mixins:[FormCustomPublic,BusEvent],
    components: {
        FormBoListPreview
    },
    props: {
        config:{
            type:Object,
            default:{}
        },
    },
    data(){
        return{
            alias: '',
            pmtAlias: '',
            params: '',
            queryAppId:'',
            key:0
        }
    },
    onShow(){
        uni.$on('onRefresh', (data) => {
            this.key++
        });
    },
    created(){
        this.$eventBus.$on('changeTree', (conf)=> {
            this.onCellClick(conf.row)
        });
        this.alias = this.config.alias;
        this.init();
    },
    methods: {
        onCellClick:Util.debounce(function (row){
            this.$eventBus.$emit("formCustomViewEvent", {component: this.config.alias, params:row});
            this.$eventBus.$off("changeTree");
        },300),
        init(params) {
            if (params) {
                this.params = Object.keys(params).map(function (key) {
                    return encodeURIComponent(key) + "=" + encodeURIComponent(params[key]);
                }).join("&");
            }
        },
        /**
         * 处理页面定制公共事件
         * @param args
         */
        handPublicReceive(args){

            let receive = this.config.receive;
            let inputParams = args.params;
            let params = {};
            //读取配置的参数
            if(receive.mapping.length==0){
                return
            }
            for (let i = 0; i < receive.mapping.length; i++) {
                let o = receive.mapping[i];
                //处理没有配置值来源的情况。
                if(inputParams[o.valueDef]){
                    params[o.name]=inputParams[o.valueDef];
                }
                else {
                    params[o.name]="";
                }
            }
            let self_=this;
            this.getParams(receive.mapping,function (data) {
                if(data){
                    for (let key in data) {
                        params[key] = data[key];
                    }
                }
                self_.init(params);
                self_.onRefresh()
            })
        },
        onRefresh(){
            this.key++
        }
    }
}
</script>

<style scoped>

</style>
